package com.walterweimod.auxiliary_attributes.mobeffect;

import com.walterweimod.auxiliary_attributes.util.ModAttributeUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

import static com.walterweimod.auxiliary_attributes.util.ModAttributeUtils.getNameAttributeUUID;

public class ArmorToughnessBoost extends MobEffect {
    private static final UUID ARMOR_TOUGHNESS_UUID = getNameAttributeUUID(
            Attributes.ARMOR_TOUGHNESS,
            "armor_toughness_boost"
    );

    protected ArmorToughnessBoost() {
        super(MobEffectCategory.BENEFICIAL, 0xFFD3D3D3);
    }

    @Override
    public @NotNull Component getDisplayName() {
        return new TextComponent("Armor Toughness Boost");
    }

    @Override
    public void addAttributeModifiers(@NotNull LivingEntity p_19478_,
                                      @NotNull AttributeMap p_19479_,
                                      int p_19480_) {
        ModAttributeUtils.addAttributeModifier(
                p_19478_,
                Attributes.ARMOR_TOUGHNESS,
                2.5D * (p_19480_ + 1),
                ARMOR_TOUGHNESS_UUID,
                AttributeModifier.Operation.ADDITION,
                false
        );

        super.addAttributeModifiers(p_19478_, p_19479_, p_19480_);
    }

    @Override
    public void removeAttributeModifiers(@NotNull LivingEntity p_19469_,
                                         @NotNull AttributeMap p_19470_,
                                         int p_19471_) {
        ModAttributeUtils.removeAttributeModifier(
                p_19469_,
                Attributes.ARMOR_TOUGHNESS,
                ARMOR_TOUGHNESS_UUID
        );

        super.removeAttributeModifiers(p_19469_, p_19470_, p_19471_);
    }
}
